The Absolute Beginners Guide To Amos ------------------------------------- Chapter Three ------------- In this chapter we will be covering variables, before you start telling yourself you`ll never understand variables it`s not half as complicated as it first seems. A variable is a letter or combination of letters and numbers that hold a numerical value. Read the last paragraph again slowly and try to understand it. Here are some examples of a variable name: A AA ABC AVARIABLE YETANOTHER F1 F1LW4 I will explain what use variables are to us in a moment so don`t worry why we use them for now just try and understand how they work. To use a variable we first have to give it a name. This can be almost anything as long as it starts with a letter and not a number and doesn`t contain spaces, if you want a space you can use the underscore charachter _ FRED_FLINTSTONE_RULES Another restriction is you must not use keywords, PRINT for example is a keyword. You can use a key word amongst other letters and numbers though for example: XPRINT5 OK, let`s call our variable F1, we must now tell Amos what value we want F1 to hold initially, this is quite straight forward we use the = sign, and then the value so let us say we want F1 to hold the value of 10: F1=10 It`s as straight forward as that. We can now chop and change the value of F1 very easily from within our program using the INC and DEC commands. INC F1 This will add 1 to the current value of F1. Let`s imagine that we have a program that counts cars that pass a motorway junction and each time a car passes we increment our counter by 1. Our variable (or counter) is F1 and to start off we want F1 to equal 0, as we haven`t started counting yet. Right we have sat down at our imaginary computer and the first car has passed so we have to add 1 to F1 we do this in Amos with INC, as described earlier, INC F1 F1 now equals 1, let`s say we now decide to go for lunch and someone else takes over our imaginary computer and they would like to know out of interest how many cars you counted, in Amos we would do this, PRINT F1 Which will PRINT the current value of F1 on the screen, the person would see that F1 equalled 1 and call you a lazy git. We will cover the printing of a variable in the next chapter. DEC is the exact opposite to INC this will subtract 1 from F1 like this, F1=1 DEC F1 PRINT F1 Do you know what the answer would be? That is right, 0. If F1 equalled 0 and you DECremented 1 from it F1 would equal -1, minus one. Now if you have understood this chapter so far you may be thinking what if I wanted to DECrement more than one off of F1 or INC more than one? Well you could of course do this, F1=10 DEC F1 DEC F1 DEC F1 DEC F1 This would leave F1 equalling 6, not very pretty and it`s time consuming isn`t it? O.k how about this, F1=10 : REM Make our variable (or counter if you like) equal 10 F1=F1-4 : REM Make our counter equal our counter-4, F1 now equals 6 REM 10=10-4 or F1=10 F1=F1+4 : REM F1 now equals 14 which is a lot shorter/neater and easier to understand, there is another way using ADD var,number and ADD var,-number commands but you have enough to cope with at the moment. Getting back to WHY we would want a number to be represented by a letter! The reason is, it`s basically the only way to manipulate numbers, You wont find many programs written in ANY language that do not use variables. Check out chapter 4 in your Amos manual for a very good description of variables for more information on the whys and wherefores of variables. Now load EXAMPLE3.Amos and experiment. End of chapter three.